package com.db4o.odbgen.plugins.java.maingenerator.typedxmlschema;

import java.util.ArrayList;
import java.util.List;

import com.db4o.internal.odbgen.StringUtils;
import com.db4o.odbgen.plugins.xmlschema.Element;

public class TSEnum implements XmlElement, TypeDeclaration{

	private List<String> _imports;
	private List<TSModifier> _modifiers;
	private Element _element;
	private String _package;
	private String _simpleName;
	private List<TSEnumConstant> _constants;
	private List<TSEnumParameter> _parameters;

	/**
	 * Constructs an enum given it's fields.
	 * @param element The corresponding element inside XmlSchema.
	 * @param packageName The name of the package.
	 * @param modifiers The modifiers used for this enum.
	 * @param simpleName The name.
	 * @param constants The list of constants.
	 * @param parameters The list of parameters.
	 */
	public TSEnum(
			Element element,
			String packageName,
			List<TSModifier> modifiers,
			String simpleName,
			List<TSEnumConstant> constants,
			List<TSEnumParameter> parameters
			){
		this._element = element;
		this._package = packageName;
		this._modifiers = modifiers;
		this._simpleName = simpleName;
		this._constants = constants;
		this._parameters = parameters;
		
		this._imports = new ArrayList<String>();

	}
	
	/**
	 * See {@link XmlElement} for details.
	 */
	@Override
	public Element getElement() {
		return this._element;
	}

	/**
	 * See {@link TypeDeclaration} for more details.
	 */
	@Override
	public String getPackage() {
		return this._package;
	}

	/**
	 * See {@link TypeDeclaration} for more details.
	 */
	@Override
	public String getQualifiedName() {
		return this._package+(this._package.length()==0?"":".")+this._simpleName;
	}

	/**
	 * See {@link TypeDeclaration} for more details.
	 */
	@Override
	public String getSimpleName() {
		return this._simpleName;
	}

	/**
	 * Returns the list of constants of this enum.
	 * This can never be null. 
	 */
	public List<TSEnumConstant> getConstants(){
		if(this._constants==null)
			this._constants = new ArrayList<TSEnumConstant>();
		return this._constants;
	}
	
	/**
	 * Returns the list of parameters for this enum.
	 * This can never be null. 
	 */
	public List<TSEnumParameter> getParameters(){
		if(this._constants==null)
			this._constants = new ArrayList<TSEnumConstant>();
		return this._parameters;
	}

	/**
	 * Returns the list of imports needed for this enum.
	 */
	public List<String> getImports(){
		return this._imports;
	}

	/**
	 * Returns the modifiers of this field.
	 */
	public List<TSModifier> getModifiers(){
		return this._modifiers;
	}
	
	/**
	 * Returns a string representing this object.
	 * This is used for debug purposes.
	 * @param tabs Number of tabs to indent.
	 */
	String toString(int tabs) {
		StringBuilder res = new StringBuilder();
		
		res.append(String.format("%senum", StringUtils.tabs(tabs)));
		res.append(StringUtils.newLine());

		res.append(String.format("%sname=%s",
				StringUtils.tabs(tabs+1),
				this.getQualifiedName()
				));
		res.append(StringUtils.newLine());
		
		for(TSEnumConstant cst : this.getConstants()){
			res.append(cst.toString(tabs+1));
			res.append(StringUtils.newLine());
		}

		for(TSEnumParameter param : this.getParameters()){
			res.append(param.toString(tabs+1));
			res.append(StringUtils.newLine());
		}
		
		return res.toString();
	}

	

}


